import tushare as ts
import requests
from helpers import getJsonForData
df = ts.get_index()
print(df)
exit(0)

res = ts.get_realtime_quotes(top=99999)
res = ts.profit_data(top=99999)
data = getJsonForData(res)
request_data = {
    'year': "2016",
    'type': "profit_data",
    'data': data,
}
print("profit_data")
print(data)
res = requests.post('http://gst.anyuzhe.com/api/external_data', request_data)
print(res.text)
exit(0)
# res = ts.get_hist_data("300040")
# res = ts.get_h_data("300040",start='2010-01-08', end='2018-03-16')

#
for year in range(2018,2020):
    month = 0
    print(str(year)+'年')
    while month<12:
        try:
            month += 1
            data = ts.xsg_data(year=year,month=month)

            data = getJsonForData(data)

            request_data = {
                'year': year,
                'month': month,
                'type': "xsg_data",
                'data': data,
            }
            print("xsg_data")
            print(data)
            res = requests.post('http://gst.anyuzhe.com/api/external_data', request_data)
            print(res.text)
        except Exception as e:
            print('xsg_data出错:' + str(year) + '--' + str(month))
#
# for year in range(2018,2020):
#     month = 0
#     print(str(year)+'年')
#     while month<12:
#         try:
#             month += 1
#             data = ts.xsg_data(year=year,month=month)
#
#             data = getJsonForData(data)
#
#             request_data = {
#                 'year': year,
#                 'month': month,
#                 'type': "xsg_data",
#                 'data': data,
#             }
#             print("xsg_data")
#             print(data)
#             res = requests.post('http://gst.anyuzhe.com/api/external_data', request_data)
#             print(res.text)
#         except Exception as e:
#             print('xsg_data出错:' + str(year) + '--' + str(month))